<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post"
			enctype="multipart/form-data">
			<input type="hidden" class="form-control" id="resumeId" name="resumeId" value="${talentsId }"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">人物关系：</label>
				<div class="col-sm-8">
					<select class="form-control" name="relationId" id="relationId">
					    <option value="0">==请选择==</option>
						<c:forEach items="${fns:getDictList('resume_relation')}"
							var="temp1">
							<option value="${temp1.value }">${temp1.valueName }</option>
						</c:forEach>
					</select>		    
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">名称：</label>
				<div class="col-sm-8">
					<select class="form-control" name="name" id="tname">
					    <option value=""></option>
					</select>		
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">时间段：</label>
				<div class="col-sm-8 form-inline"  id="times">
				    <span> 开始时间 </span><input type="text" class="form-control"><span> --结束时间</span><input type="text" class="form-control">		
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">查询</button>
				</div>
			</div>
			
			<%-- <div class="form-group">
				<label class="col-sm-3 control-label">姓名：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="name" name="name" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">人才ID：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="resumeId" name="resumeId" value="${talentsId }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">关系人才ID：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="resumeRelationId" name="resumeRelationId" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">人物关系ID：</label>
				<div class="col-sm-8">
					<select class="form-control" name="relationId" id="relationId">
						<c:forEach items="${fns:getDictList('resume_relation')}"
							var="temp1">
							<option value="${temp1.value }">${temp1.valueName }</option>
						</c:forEach>
					</select>		    
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="remark" name="remark" />
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div> --%>
		</form>
	</div>


	<script>
    $(function () {
    	var talentid = $("#resumeId").val();
		var result;
		var name="";
		var temp;
    	$("#relationId").change(function(){
    		var htm='<option value="">==请选择==</option>';
    		temp = $("#relationId").val();	
    		if(temp==1){
    			$.ajax({
    				 url: '<%=contextPath%>/work/getJsonBy',
    				 data:{'talentsId':talentid},
    				 type : 'post',
    				 dataType : "json",
    				 success : function(data) {
    						console.log(data.datas);
    						result = data.datas;
    						console.log(data.datas[0].company.name);
    						for (var i = 0; i < result.length; i++) {
    							name = result[i].companyName;
    							if(name==null){
    								name = result[i].company.name;
    							}
    							htm +='<option value="'+name+'">'+name+'</option>';
							}
    						$("#tname").html(htm);
    					}
    			});
    		}else if(temp==2){
    			$.ajax({
   				 url: '<%=contextPath%>/edu/getJsonBy',
   				 data:{'talentsId':talentid},
   				 type : 'post',
   				 dataType : "json",
   				 success : function(data) {
   						console.log(data.datas);
   						result = data.datas;
						for (var i = 0; i < result.length; i++) {
							name = result[i].schoolName;
							if(name==null){
								name = result[i].school.name;
							}
							htm +='<option value="'+name+'">'+name+'</option>';
						}
						$("#tname").html(htm);
   					}
   			});
			}
    	});
    	
    	$("#tname").change(function(){
    		var tname =$("#tname").val();
    		var htm_time="";
    		if(temp==1){
    		$.ajax({
				 url: '<%=contextPath%>/work/getJsonBy',
				 data:{
					 'talentsId':talentid,
					 'name':tname
				 },
				 type : 'post',
				 dataType : "json",
				 success : function(data) {
						result = data.datas;
						for (var i = 0; i < result.length; i++) {
							htm_time +='<span> 开始时间 </span><input type="text" class="form-control" value="'+result[i].startDate+'" name="startDate'+i+'"><span> --结束时间</span><input type="text" class="form-control" value="'+result[i].endDate+'" name="endDate'+i+'">';
						}
						$("#times").html(htm_time);
					}
			});
    		}else if (temp==2) {
    			$.ajax({
   				 url: '<%=contextPath%>/edu/getJsonBy',
   				 data:{
   					 'talentsId':talentid,
   					 'name':tname
   				 },
   				 type : 'post',
   				 dataType : "json",
   				 success : function(data) {
   						result = data.datas;
   						for (var i = 0; i < result.length; i++) {
   							htm_time +='<span> 开始时间 </span><input type="text" class="form-control" value="'+result[i].startDate+'" name="startDate'+i+'"><span> --结束时间</span><input type="text" class="form-control" value="'+result[i].endDate+'" name="endDate'+i+'">';
   						}
   						$("#times").html(htm_time);
   					}
   			});
			}
    	});
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('name','姓名未填写!'),
        	  new Array('resumeId','人才ID未填写!'),
        	  new Array('relationId','人物关系ID未填写!')
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/relationship/add',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
	});
	</script>
</body>
</html>